WTL Controls
Back to the WTL Controls Home Page.
BIS_WTL_CONTROLS::CODStatic Class Reference

An owner-drawn CStatic descendant, providing custom background and text colors and edge styles. More...

#include <ODStatic.h>

Inheritance diagram for BIS_WTL_CONTROLS::CODStatic:

Public Member Functions

 CODStatic () noexcept
 
virtual ~CODStatic ()
 
void SubclassStatic (HWND hWnd)
 Subclass a Static Text control. More...
 
void UnSubclassStatic ()
 Un-subclass the window and release GDI resources. More...
 
void SetBtnFaceBkgnd (bool value)
 Set or clear the UseBtnFaceBkgnd state. A call to UpdateContent may be required to make the new state apparent. More...
 
bool GetBtnFaceBkgnd () const
 Default: false. More...
 
void SetBackColor (COLORREF value)
 Set a new background color. A call to UpdateContent may be required to make the new color visible. More...
 
COLORREF GetBackColor () const
 Default: COLOR_BTNFACE. More...
 
void SetTextColor (COLORREF value)
 Set a new text color. A call to UpdateContent may be required to make the new color visible. More...
 
COLORREF GetTextColor () const
 Default: COLOR_WINDOWTEXT. More...
 
void SetCaption (LPCTSTR text)
 Set a new string to display. A call to UpdateContent may be required to make the new caption visible. More...
 
std::basic_string< TCHAR > GetCaption () const
 Default: "". More...
 
void SetMultilineEnabled (bool value)
 If false, the DT_SINGLELINE flag will be included in calls to DrawText (or DrawThemeText).
A call to UpdateContent may be required to make changes visible. More...
 
bool GetMultilineEnabled () const
 Default: false. More...
 
void SetEndEllipsisEnabled (bool value)
 If true, the DT_END_ELLIPSIS flag will be included in calls to DrawText (or DrawThemeText). A call to UpdateContent may be required to make changes visible. More...
 
bool GetEndEllipsisEnabled () const
 Default: false. More...
 
void SetPathEllipsisEnabled (bool value)
 If true, the DT_PATH_ELLIPSIS flag will be included in calls to DrawText (or DrawThemeText). A call to UpdateContent may be required to make changes visible. More...
 
bool GetPathEllipsisEnabled () const
 Default: false. More...
 
void SetHorzTextAlignment (CHorzAlignment value)
 The CHorzAlignment member variable state will result in either the DT_CENTER, DT_LEFT or DT_RIGHT flag being included in calls to DrawText (or DrawThemeText), as appropriate. A call to UpdateContent may be required to make changes visible. More...
 
CHorzAlignment GetHorzTextAlignment () const
 Default: CHorzAlignment::haMiddle. More...
 
void SetVertTextAlignment (CVertAlignment value)
 The CVertAlignment member variable state will result in either the DT_BOTTOM, DT_TOP or DT_VCENTER flag being included in calls to DrawText (or DrawThemeText), as appropriate. A call to UpdateContent may be required to make changes visible. More...
 
CVertAlignment GetVertTextAlignment () const
 Default: CVertAlignment::vaLeft. More...
 
void SetEdgeStyle (CEdgeStyle style)
 The EdgeStyle state determines the type of graphic boundary indicator surrounding the control in it's parent dialog or property page. More...
 
CEdgeStyle GetEdgeStyle () const
 Default: CEdgeStyle::esLine. More...
 
void SetVerticalMargin (int margin)
 Sets top and bottom text margin inside window edge. A call to UpdateContent may be required to make changes visible. More...
 
int GetVerticalMargin () const
 Default: 0. More...
 
void SetHorizontalMargin (int margin)
 Sets left and right text margin inside window edge. A call to UpdateContent may be required to make changes visible. More...
 
int GetHorizontalMargin () const
 Default: 0. More...
 
void UseThemedStyle (bool val)
 If true, content will be painted using DrawThemeBackground and DrawThemeText, rather than the older FillRect and DrawText APIs. More...
 
bool IsUsingThemedStyle () const
 Default: false. More...
 
void SetThemedBackgroundStyle (CThemedBackgroundStyle val)
 Set the ThemedBackgroundStyle to a new value. More...
 
CThemedBackgroundStyle GetThemedBackgroundStyle () const
 Default: tbMainInstructionPane. More...
 
void SetThemedTextStyle (CThemedTextStyle val)
 Set the ThemedTextStyle to a new value. More...
 
CThemedTextStyle GetThemedTextStyle () const
 Default: ttMainInstruction. More...
 
void UpdateContent ()
 Wraps calls to Invalidate and UpdateWindow, forcing a repaint, updating the back buffer and blitting the new contents to the window. More...
 

Detailed Description

An owner-drawn CStatic descendant, providing custom background and text colors and edge styles.

This CStatic descendant also descends from COwnerDraw, and performs custom drawing by implementing OnDrawItem. Custom double-buffering is provided; changes to appearance may not be visible until a repaint is forced by calling UpdateContent.

The member function SubclassStatic reads the sub-classed window's style, and modifies it to include the SS_OWNERDRAW and SS_NOTIFY flags. It also sets or clears the HorzTextAlignment, MultilineEnabled and EndEllipsis member variables as follows:

  • If the SS_CENTER flag is present, horizontal alignment will be haCenter; otherwise, if SS_RIGHT or WS_EX_RIGHT are present, horizontal alignment will be haRight; otherwise, horizontal alignment will be haLeft.
  • If SS_LEFTNOWORDWRAP is present, MultlineEnabled will be set false and the horizontal alignment will be set to haLeft, as described above.
  • If SS_ENDELLIPSIS is present, EndEllipsis is set true, horizontal alignment will be haLeft and MultilineEnabled will be set false.

These modifications are consistent with the behavior of the GDI API DrawText, which is used when painting the control. Note that you can change CODStatic properties to violate the DrawText rules (e.g., set MultilineEnabled and EndEllipsisEnabled both true), but DrawText will ignore illegal requests.

Vertical alignment settings will be ignored if MultilineEnabled is true; only vaTop is valid unless MultilineEnabled is false.

The text content itself is accessed through the runtime Caption property, NOT the inherited SetWindowText member. The Caption contents are initialized with a call to GetWindowText, so strings loaded through the IDE at design time are faithfully displayed.

Window edge styles defined with window or control style flags (e.g.: SS_ETCHEDFRAME or WS_MODALFRAME) will overwrite edges defined by setting the EdgeStyle property. Use the EdgeStyle property OR windows style flags to define an edge, not both.

If UseThemedStyle is set true (default: false), the control will be drawn using the DrawThemeBackground and DrawThemeText API, rather than the older GDI FillRect and DrawText API.

Another point to remember is the BtnFaceBkgnd property ( false by default). If this is true (and UseThemedStyle is false), it will override attempts to change background color, forcing COLOR_BTNFACE.

Finally, the dialog container must reflect WM_DRAWITEM messages back to the control, either with the non-discriminating REFLECT_NOTIFICATIONS_EX, or with something more selective (e.g, REFLECT_NOTIFICATIONS_MSG_ID_FILETERED).

Typical usage is depicted below.

CODStatic odStat1;
odStat1.SubclassStatic(GetDlgItem(IDC_STAT1));
odStat1.SetMultilineEnabled(true);
odStat1.SetBackColor(COLOR_RED);
odStat1.SetTextColor(COLOR_WHITE);
.
.
.
odStat1.UnSubclassStatic(); // when finished using the control (probably in OnEndDialog).

Definition at line 82 of file ODStatic.h.

Constructor & Destructor Documentation

◆ CODStatic()

BIS_WTL_CONTROLS::CODStatic::CODStatic ( )
noexcept

Definition at line 20 of file ODStatic.cpp.

◆ ~CODStatic()

BIS_WTL_CONTROLS::CODStatic::~CODStatic ( )
virtual

Definition at line 57 of file ODStatic.cpp.

Member Function Documentation

◆ SubclassStatic()

void BIS_WTL_CONTROLS::CODStatic::SubclassStatic ( HWND  hWnd)

Subclass a Static Text control.

SubclassStatic also modifies the controls window style to make it owner-drawn and ensure proper notifications are sent by the control, and finally, to set internal state to match as well as possible the design-time window styles flags set for the control.

See the main CODStatic class documentation for more details.

Parameters
hWndWindow handle to the Static Text control take over.
Return values
void

Definition at line 86 of file ODStatic.cpp.

◆ UnSubclassStatic()

void BIS_WTL_CONTROLS::CODStatic::UnSubclassStatic ( )

Un-subclass the window and release GDI resources.

Use this method to properly release the subclassed window and other resources.

Definition at line 129 of file ODStatic.cpp.

◆ SetBtnFaceBkgnd()

void BIS_WTL_CONTROLS::CODStatic::SetBtnFaceBkgnd ( bool  value)

Set or clear the UseBtnFaceBkgnd state. A call to UpdateContent may be required to make the new state apparent.

If UseThemedStyle is false and UseBtnFaceBkgnd is true, the control's background will be painted with the current COLOR_BTNFACE value, regardless of the control's BacKColor value. (Note that if UseBtnFaceBkgnd is true, the control will respond to WM_SYSCOLOR_CHANGE and WM_THEMECHANGED messages and will update the color used to paint the background of the control in the event that the user changes the system theme. Text color will NOT automatically change, so if the intent is to have a control with both system button face background and button text colors(COLOR_BTNTEXT), you'll have to handle the WM_SYSCOLORCHANGE and MSG_THEMECHANGED messages yourself, and load the new text color into the control's TextColor property.)

If UseThemedStyle is true, this value is ignored.

Parameters
valueNew bool state.
Return values
void

Definition at line 175 of file ODStatic.cpp.

◆ GetBtnFaceBkgnd()

bool BIS_WTL_CONTROLS::CODStatic::GetBtnFaceBkgnd ( ) const

Default: false.

Return values
boolCurrent UseBtnFaceBkgnd state.

Definition at line 152 of file ODStatic.cpp.

◆ SetBackColor()

void BIS_WTL_CONTROLS::CODStatic::SetBackColor ( COLORREF  value)

Set a new background color. A call to UpdateContent may be required to make the new color visible.

Note that the value set here can be overridden if either BtnFaceBkgnd or UseThemedStyle are true.

Parameters
valueNew background color.
Return values
void

Definition at line 207 of file ODStatic.cpp.

◆ GetBackColor()

COLORREF BIS_WTL_CONTROLS::CODStatic::GetBackColor ( ) const

Default: COLOR_BTNFACE.

Return values
COLORREFCurrent BackColor.

Definition at line 192 of file ODStatic.cpp.

◆ SetTextColor()

void BIS_WTL_CONTROLS::CODStatic::SetTextColor ( COLORREF  value)

Set a new text color. A call to UpdateContent may be required to make the new color visible.

Note that the value set here can be overridden if UseThemedStyle is true.

Parameters
valueThe new text color.
Return values
void

Definition at line 240 of file ODStatic.cpp.

◆ GetTextColor()

COLORREF BIS_WTL_CONTROLS::CODStatic::GetTextColor ( ) const

Default: COLOR_WINDOWTEXT.

Return values
COLORREFCurrent TextColor.

Definition at line 225 of file ODStatic.cpp.

◆ SetCaption()

void BIS_WTL_CONTROLS::CODStatic::SetCaption ( LPCTSTR  text)

Set a new string to display. A call to UpdateContent may be required to make the new caption visible.

The Caption contents will be initialized with a call to GetWindowText, but changes to the displayed text after the control is subclassed must be made through the Caption property; SetWindowText will have no effect.

Parameters
textThe new text to display.
Return values
void

Definition at line 274 of file ODStatic.cpp.

◆ GetCaption()

std::basic_string< TCHAR > BIS_WTL_CONTROLS::CODStatic::GetCaption ( ) const

Default: "".

Return values
std::basic_string<TCHAR>Current Caption content.

Definition at line 258 of file ODStatic.cpp.

◆ SetMultilineEnabled()

void BIS_WTL_CONTROLS::CODStatic::SetMultilineEnabled ( bool  value)

If false, the DT_SINGLELINE flag will be included in calls to DrawText (or DrawThemeText).
A call to UpdateContent may be required to make changes visible.

See the documentation for the GDI DrawText API for more information.

Parameters
valueSet/clear internal flag used to wrap text to multiple lines.
Return values
void

Definition at line 307 of file ODStatic.cpp.

◆ GetMultilineEnabled()

bool BIS_WTL_CONTROLS::CODStatic::GetMultilineEnabled ( ) const

Default: false.

Return values
boolCurrent MultiLineEnabled state.

Definition at line 291 of file ODStatic.cpp.

◆ SetEndEllipsisEnabled()

void BIS_WTL_CONTROLS::CODStatic::SetEndEllipsisEnabled ( bool  value)

If true, the DT_END_ELLIPSIS flag will be included in calls to DrawText (or DrawThemeText). A call to UpdateContent may be required to make changes visible.

See the documentation for the GDI DrawText API for more information.

Parameters
valueNew bool state.
Return values
void

Definition at line 340 of file ODStatic.cpp.

◆ GetEndEllipsisEnabled()

bool BIS_WTL_CONTROLS::CODStatic::GetEndEllipsisEnabled ( ) const

Default: false.

Return values
boolCurrent EndEllipsisEnabled state.

Definition at line 324 of file ODStatic.cpp.

◆ SetPathEllipsisEnabled()

void BIS_WTL_CONTROLS::CODStatic::SetPathEllipsisEnabled ( bool  value)

If true, the DT_PATH_ELLIPSIS flag will be included in calls to DrawText (or DrawThemeText). A call to UpdateContent may be required to make changes visible.

See the documentation for the GDI DrawText API for more information.

Parameters
valueNew bool state.
Return values
void

Definition at line 373 of file ODStatic.cpp.

◆ GetPathEllipsisEnabled()

bool BIS_WTL_CONTROLS::CODStatic::GetPathEllipsisEnabled ( ) const

Default: false.

Return values
boolCurrent PathEllipsisEnabled state.

Definition at line 357 of file ODStatic.cpp.

◆ SetHorzTextAlignment()

void BIS_WTL_CONTROLS::CODStatic::SetHorzTextAlignment ( CHorzAlignment  value)

The CHorzAlignment member variable state will result in either the DT_CENTER, DT_LEFT or DT_RIGHT flag being included in calls to DrawText (or DrawThemeText), as appropriate. A call to UpdateContent may be required to make changes visible.

See the documentation for the GDI DrawText API for more information.

Parameters
valueNew CHorzAlignment.
Return values
void

Definition at line 407 of file ODStatic.cpp.

◆ GetHorzTextAlignment()

CHorzAlignment BIS_WTL_CONTROLS::CODStatic::GetHorzTextAlignment ( ) const

Default: CHorzAlignment::haMiddle.

Return values
CHorzAlignmentCurrent Horizontal Alignment.

Definition at line 390 of file ODStatic.cpp.

◆ SetVertTextAlignment()

void BIS_WTL_CONTROLS::CODStatic::SetVertTextAlignment ( CVertAlignment  value)

The CVertAlignment member variable state will result in either the DT_BOTTOM, DT_TOP or DT_VCENTER flag being included in calls to DrawText (or DrawThemeText), as appropriate. A call to UpdateContent may be required to make changes visible.

See the documentation for the GDI DrawText API for more information.

Parameters
valueNew CVertAlignment.
Return values
void

Definition at line 442 of file ODStatic.cpp.

◆ GetVertTextAlignment()

CVertAlignment BIS_WTL_CONTROLS::CODStatic::GetVertTextAlignment ( ) const

Default: CVertAlignment::vaLeft.

Return values
CVertAlignmentCurrent Vertical Alignment.

Definition at line 425 of file ODStatic.cpp.

◆ SetEdgeStyle()

void BIS_WTL_CONTROLS::CODStatic::SetEdgeStyle ( CEdgeStyle  style)

The EdgeStyle state determines the type of graphic boundary indicator surrounding the control in it's parent dialog or property page.

Note that window or control style flags such as WS_MODALFRAME or SS_ETCHEDFRAME will result in the owner-drawn edges being overwritten. Use either the EdgeStyle property or window/control style flags to define a control's edge style, but not both.

Parameters
style
Return values
void

Definition at line 477 of file ODStatic.cpp.

◆ GetEdgeStyle()

CEdgeStyle BIS_WTL_CONTROLS::CODStatic::GetEdgeStyle ( ) const

Default: CEdgeStyle::esLine.

Return values
CEdgeStyleCurrent EdgeStyle.

Definition at line 459 of file ODStatic.cpp.

◆ SetVerticalMargin()

void BIS_WTL_CONTROLS::CODStatic::SetVerticalMargin ( int  margin)

Sets top and bottom text margin inside window edge. A call to UpdateContent may be required to make changes visible.

Parameters
margin
Return values
void

Definition at line 508 of file ODStatic.cpp.

◆ GetVerticalMargin()

int BIS_WTL_CONTROLS::CODStatic::GetVerticalMargin ( ) const

Default: 0.

Return values
intThe current Vertical Margin.

Definition at line 494 of file ODStatic.cpp.

◆ SetHorizontalMargin()

void BIS_WTL_CONTROLS::CODStatic::SetHorizontalMargin ( int  margin)

Sets left and right text margin inside window edge. A call to UpdateContent may be required to make changes visible.

Parameters
margin
Return values
void

Definition at line 539 of file ODStatic.cpp.

◆ GetHorizontalMargin()

int BIS_WTL_CONTROLS::CODStatic::GetHorizontalMargin ( ) const

Default: 0.

Return values
intThe current Horizontal Margin.

Definition at line 525 of file ODStatic.cpp.

◆ UseThemedStyle()

void BIS_WTL_CONTROLS::CODStatic::UseThemedStyle ( bool  val)

If true, content will be painted using DrawThemeBackground and DrawThemeText, rather than the older FillRect and DrawText APIs.

A call to UpdateContent may be required to make changes visible.

Definition at line 570 of file ODStatic.cpp.

◆ IsUsingThemedStyle()

bool BIS_WTL_CONTROLS::CODStatic::IsUsingThemedStyle ( ) const

Default: false.

Return values
boolThe current UseThemedStyle state.

Definition at line 556 of file ODStatic.cpp.

◆ SetThemedBackgroundStyle()

void BIS_WTL_CONTROLS::CODStatic::SetThemedBackgroundStyle ( CThemedBackgroundStyle  val)

Set the ThemedBackgroundStyle to a new value.

The CThemedBackgroundStyle enumerants correspond to select TaskDialog Parts, as indicated below:

• CThemedBackgroundStyle::tbPrimaryPanel TDLG_PRIMARYPANEL
• CThemedBackgroundStyle::tbMainInstructionPane TDLG_MAININSTRUCTIONPANE
• CThemedBackgroundStyle::tbContentPane TDLG_CONTENTPANEL
• CThemedBackgroundStyle::tbSecondaryPanel TDLG_SECONDARYPANEL
• CThemedBackgroundStyle::tbControlPane TDLG_CONTROLPANE
A call to UpdateContent may be required to make changes visible.

For more information, see Parts and States in the MSDN Windows Controls Visual Styles Reference.

Parameters
valThe new CThemedBackgroundStyle.
Return values
void

Definition at line 620 of file ODStatic.cpp.

◆ GetThemedBackgroundStyle()

CThemedBackgroundStyle BIS_WTL_CONTROLS::CODStatic::GetThemedBackgroundStyle ( ) const

Default: tbMainInstructionPane.

Return values
CThemedBackgroundStyleThe current ThemedBackStyle.

Definition at line 587 of file ODStatic.cpp.

◆ SetThemedTextStyle()

void BIS_WTL_CONTROLS::CODStatic::SetThemedTextStyle ( CThemedTextStyle  val)

Set the ThemedTextStyle to a new value.

The CThemedTextStyle enumerants correspond to select TextStyle Parts and States, as indicated below:

EnumerantPartStyle
• CThemedTextStyle::ttMainInstruction TEXT_MAININSTRUCTION0
• CThemedTextStyle::ttInstruction TEXT_INSTRUCTION0
• CThemedTextStyle::ttBodyTitle TEXT_BODYTITLE0
• CThemedTextStyle::ttBodyText TEXT_BODYTEXT0
• CThemedTextStyle::ttSecondaryText TEXT_SECONDARYTEXT0
• CThemedTextStyle::ttLabel TEXT_LABEL0
• CThemedTextStyle::ttControlLabel_Normal TEXT_CONTROLLABELTS_CONTROLLABEL_NORMAL
• CThemedTextStyle::ttControlLabel_Disabled TEXT_CONTROLLABELTS_CONTROLLABEL_DISABLED
A call to UpdateContent may be required to make changes visible.

For more information, see Parts and States in the MSDN Windows Controls Visual Styles Reference.

Parameters
valThe new CThemedTextStyle.
Return values
void

Definition at line 677 of file ODStatic.cpp.

◆ GetThemedTextStyle()

CThemedTextStyle BIS_WTL_CONTROLS::CODStatic::GetThemedTextStyle ( ) const

Default: ttMainInstruction.

Return values
CThemedTextStyleThe current ThemedTextStyle.

Definition at line 637 of file ODStatic.cpp.

◆ UpdateContent()

void BIS_WTL_CONTROLS::CODStatic::UpdateContent ( )

Wraps calls to Invalidate and UpdateWindow, forcing a repaint, updating the back buffer and blitting the new contents to the window.

Definition at line 693 of file ODStatic.cpp.


The documentation for this class was generated from the following files: